export default class ProgressHud {
	static showLoading(text) {
		uni.showLoading({
			title:text || '加载中...'
		});
	}
	
	static hideLoading() {
		uni.hideLoading();
	}
	static showModal(options) {
		var settings = {
			title: '提示',
			content: options.text, 
			showCancel:true,
		};
		Object.assign(settings,options)
		if(options.success){
			settings.success = options.success;
		}
		uni.showModal(settings);
	}
	static alert(text, success = ()=>{}) {
		var settings = {
			title: '提示',
			content: text, 
			showCancel:false,
			success:success
		};
	 
		this.showModal(settings);
	}
	static alert(options) {
		var settings = {
			title: '提示',
			content: options.text, 
			showCancel:false,
		};
		Object.assign(settings,options)
		if(options.success){
			settings.success = options.success;
		}
		uni.showModal(settings);
	}
	
	static showToast(text) {
		uni.showToast({
			title:text,
			icon:"none",
			duration:2000
		});
	}
	
	static showToast(text,duration) {
		uni.showToast({
			title:text,
			icon:"none",
			duration:duration || 2000
		});
	}
	
	static showToast(text, duration, completion) {
		uni.showToast({
			title:text,
			icon:"none",
			duration:duration || 2000,
			complete:completion
		});
	}
	static successToast(text,duration) {
		uni.showToast({
			title:text,
			icon:"success",
			duration:duration || 2000
		});
	}
	static successToast(text,duration, completion) {
		uni.showToast({
			title:text,
			icon:"success",
			duration:duration || 2000,
			complete:completion
		});
	}
	static showErrorInfo(err) {
		if(typeof err === 'object') {
			if(err.hasOwnProperty('errMsg')) {
				if(!err.errMsg) {
					uni.showToast({
						title:"网络错误",
						icon:'none',
						duration:2000
					});
				} else {
					uni.showToast({
						title:err.errMsg,
						icon:'none',
						duration:2000
					});
				}
			} else {
				uni.showToast({
					title:JSON.stringify(err),
					icon:'none',
					duration:2000
				});
			}
		} else {
			uni.showToast({
				title:err,
				icon:'none',
				duration:2000
			});
		}
	}
}